﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Utilities;

namespace PIT.Labs.SharePoint.Extensions.Helper
{
    /// <summary>
    /// Extends the <see cref="T:Microsoft.SharePoint.Utilities.SPUtility"/> class.
    /// </summary>
    public static class SPUtilityHelper
    {
        /// <summary>
        /// Retrieves the value for a named resource string from the resource file for a specified language.
        /// </summary>
        /// <param name="resourceName">The keyname of the resource.</param>
        /// <param name="resourceFile">The base file name of the language resource file containing a localized string value.
        /// For example, if you have a series of resource files named <c>myresources.en-us.resx</c>, <c>myresources.es-es.resx</c>, <c>myresources.de-de.resx</c>, and so on, the value to pass in this parameter is <c>myresources</c>.
        /// </param>
        /// <returns>
        /// If the named resource does not have a value for the specified language, 
        /// it returns the value for the invariant language.
        /// If the named resource does not exist, it returns the original expression.
        /// </returns>
        /// <seealso cref="Microsoft.SharePoint.Utilities.SPUtility.GetLocalizedString(string,string,uint)"/>
        public static String GetLocalizedString(String resourceName, String resourceFile)
        {
            if (String.IsNullOrEmpty(resourceName) || String.IsNullOrEmpty(resourceFile))
                return String.Empty;

            String resourceExpression = String.Format("$Resources:{0}", resourceName);

            return SPUtility.GetLocalizedString(resourceExpression, resourceFile, (uint)System.Globalization.CultureInfo.CurrentUICulture.LCID);
        }
    }
}
